#include "StdAfx.h"
#include "Device.h"
#include "MonitorMessage.h"
#include "MonitorPlatform.h"

CDevice::CDevice(DWORD dwID, UINT nType, LPCTSTR lpszDeviceName, int nChannelNumber)
	: IBaseClass(IBaseClass::CLASS_DEVICE)
	, m_dwID(dwID)
	, m_nType(nType)
	, m_strDeviceName(lpszDeviceName)
	, m_nChannelNumber(nChannelNumber)
	, m_bIsOnline(FALSE)
	, m_bIsLastOnline(FALSE)
	, m_bAvailable(FALSE)
	, m_dwImageAdjustInterfaceType(IMAGE_ADJUST_INTERFACE_RANDOM)
	, m_bNew(FALSE)
	, m_pMonitorCenter(NULL)
{
}

CDevice::~CDevice(void)
{
}


void CDevice::GetImageAdjustParamRange(int& nMin, int& nMax)
{
	nMin = 0;
	nMax = 255;
}

void CDevice::SetOnline(BOOL bOnline)
{
	if(m_bAvailable)
	{
		m_bIsOnline = bOnline;
		CChannelList::iterator it = m_ChannelList.begin();
		if(bOnline)
		{
			for(; it != m_ChannelList.end(); ++it)
			{
				(*it)->SetState(0, CS_ONLINE);
			}
		}
		else
		{
			for(; it != m_ChannelList.end(); ++it)
			{
				(*it)->SetState(CS_ONLINE, 0);
			}
		}
	}
}

void CDevice::SetDevOnLineOnly(BOOL bOnline)
{
	if(m_bAvailable && m_bIsOnline != bOnline)
	{
		m_bIsOnline = bOnline;
		CPlatformMessage Message(DEVICE_STATE_CHANGED, this);
		Message.m_pChannel = GetChannel(0);
		Message.Send();
	}
}

void CDevice::SetDeviceInfo(CString szName, DWORD ID)
{
	m_strDeviceName = szName;
	m_dwID = ID;
}

void CDevice::AddChannel(CChannel* pChannel)
{	
	m_ChannelList.push_back(pChannel);
	pChannel->SetDevice(this); 
	m_nChannelNumber++;
}

void CDevice::InitDevice()
{
	m_bAvailable = TRUE;
}
